package com.ydm.myapp001.utils;


import com.ydm.myapp001.BuildConfig;

public class AppLogger {
    private static final boolean DEBUG = BuildConfig.DEBUG;
    private static final String tagPrefix = "MySelfLog_";
    private AppLogger() {
    }

    /**
     * Send an INFO log message.
     *
     * @param tag The tag you would like logged.
     * @param msg The message you would like logged.
     */
    public static void i(String tag, String msg) {
        if (DEBUG)
            android.util.Log.i(tagPrefix+tag, msg);
    }

    /**
     * Send a ERROR log message.
     *
     * @param tag The tag you would like logged.
     * @param msg The message you would like logged.
     */
    public static void e(String tag, String msg) {
        if (DEBUG)
            android.util.Log.e(tagPrefix+tag, msg);
    }

    /**
     * Send a DEBUG log message.
     *
     * @param tag The tag you would like logged.
     * @param msg The message you would like logged.
     */
    public static void d(String tag, String msg) {
        //信息太长,分段打印
        //因为String的length是字符数量不是字节数量所以为了防止中文字符过多，
        //把4*1024的MAX字节打印长度改为2001字符数
        int max_str_length = 2001 - tag.length();

        if (DEBUG) {
            //大于4000时
            while (msg.length() > max_str_length) {
                android.util.Log.d(tagPrefix + tag, msg.substring(0, max_str_length));
                msg = msg.substring(max_str_length);
            }
            //剩余部分
            android.util.Log.d(tagPrefix + tag, msg);
        }
    }

    /**
     * Send a VERBOSE log message.
     *
     * @param tag The tag you would like logged.
     * @param msg The message you would like logged.
     */
    public static void v(String tag, String msg) {
        if (DEBUG)
            android.util.Log.v(tagPrefix+tag, msg);
    }

    /**
     * Send a WARN log message.
     *
     * @param tag The tag you would like logged.
     * @param msg The message you would like logged.
     */
    public static void w(String tag, String msg) {
        if (DEBUG)
            android.util.Log.w(tagPrefix+tag, msg);
    }

}
